package com.blog.controller.backend;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.blog.entity.AdminUser;
import com.blog.entity.User;
import com.blog.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@RequestMapping("backend/user")
@Controller("backendUserController")
public class UserController extends BaseController {

    @Autowired
    public UserService userService;


    @RequestMapping("/index")
    public String index(Model model, Integer curPage) {
        model.addAttribute("page", userService.getUsers(new Page<User>(curPage == null ? 1 : curPage, 5), User.STATUS_ACTIVE));
        return "backend/user/index";
    }

    @RequestMapping("/view")
    public String view(Integer id, Model model) {
        model.addAttribute("user", userService.view(id));
        return "backend/user/view";
    }

    @RequestMapping("/forbidden")
    public String delete(Integer id) {
        userService.forbidden(id);
        return "redirect:/backend/user/index";
    }

    @RequestMapping("/access")
    public String access(Integer id) {
        userService.access(id);
        return "redirect:/backend/user/index";
    }
}
